#include "CESParser.h"
#include "CTSBuilder.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char *argv[])
{

	/* initialize random seed: */
	srand ( time(NULL) );

	std::set<unsigned int> pids;
	pids.insert(52);
	pids.insert(68);
	pids.insert(49);
	pids.insert(65);
	CESParser cEsParser("C:\\1080i.mpg");
	CTSBuilder cTSBuilder(pids);


	char buffer [33];
	itoa (ERROR_PROBABILITY,buffer,10);
	string outputFile("C:\\1080i_with_errors_");
	outputFile+= buffer;
	outputFile+= ".mpg";

	FILE* pOutputFile = fopen (outputFile.c_str()
		, "wb");
	if (pOutputFile == NULL){exit (-1);}
	bool bTSErr = true;

	while (cEsParser.readData()){
		cTSBuilder.findTS(cEsParser);
		for (int i=0; i<cTSBuilder.m_mTs.size(); i++){
			CTS* cTS = cTSBuilder.m_mTs[i];

			fwrite(cTS->m_data, 1, 188, pOutputFile);

			delete cTS;
		}
		cTSBuilder.m_mTs.clear();
	}
}

